package com.xxx.modules.sys.controller;

import com.xxx.common.utils.R;
import com.xxx.modules.sys.domain.SysUserLabelDomain;
import com.xxx.modules.sys.service.SysUserLabelService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/** 标签 Controller
 * Created by ChenXuefei on 2017/10/16.
 */
@RestController
@Slf4j
public class SysUserLabeController {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private SysUserLabelService sysUserLabelService;


    /* 标签表的单表增删改查操作*/
    @RequestMapping("sys/user/label/query")
    public R selectLabelByUserId(String userId){
        //用户id怎么获取到？
        log.debug("【 开始查询标签 】");
        SysUserLabelDomain sysUserLabelDomain = new SysUserLabelDomain();
        sysUserLabelDomain.setUserId(Long.valueOf(userId));
        List<SysUserLabelDomain> sysUserLabelDomains = sysUserLabelService.queryByList(sysUserLabelDomain);

        log.debug("【 查询标签结束, "+userId +"总共有 "+sysUserLabelDomains.size()+ " 个标签 】");
        return R.ok().put("label",sysUserLabelDomains);
    }

    @RequestMapping("sys/user/label/add")
    public R addLabel(SysUserLabelDomain sysUserLabelDomain){
        //用户id怎么获取到？
        log.debug("【 开始新增标签 】");

        sysUserLabelDomain.setCreateTime(new Date());
        sysUserLabelDomain.setUpdateTime(sysUserLabelDomain.getCreateTime());
        sysUserLabelService.add(sysUserLabelDomain);

        log.debug("【 新增标签结束 】");
        return R.ok();
    }

    @RequestMapping("sys/user/label/update")
    public R updateLabel(SysUserLabelDomain sysUserLabelDomain){
        //用户id怎么获取到？
        log.debug("【 开始修改标签 】");
        sysUserLabelDomain.setUpdateTime(new Date());
        sysUserLabelService.updateBySelective(sysUserLabelDomain);

        log.debug("【 修改标签结束 】");
        return R.ok();
    }

    @RequestMapping("sys/user/label/delete")
    public R deleteLabel(String labelId){
        //用户id怎么获取到？
        log.debug("【 开始删除标签 】");
        sysUserLabelService.delete(labelId);
        log.debug("【 删除标签结束 】");
        return R.ok();
    }
}
